<?php
/**
 * Created By Project
 * Author: 陈东
 * Copyright：陈东
 * Source Code：陈东
 * Explain：I shall not authorize for any other commercial purposes, law breakers must be prosecuted.
 */
namespace Home\Controller;
use Think\Controller;

class MyprizeController extends Controller {

    public function index(){
		
		$telinfo = D(C('TABLE_TELINFO'));
		$userinfo = $_COOKIE['user_userinfo'];
		$res = $telinfo->where(array('useropenid'=>$userinfo))->find();
		$userid = $res['id'];
		//dump($this->useridtorandnumber(79,$userid));
		$this->assign('prize',$this->useridtorandnumber(260,$userid));
		$this->display();
    }
	protected function useridtorandnumber($rootid,$userid){
		$randnumber = D(C('TABLE_RANDNUMBER'));
		$where['iswhoget'] = $userid;
		$where['ma_rootid'] = $rootid;
		$res = $randnumber->distinct(true)->field('ma_type,ma_randnumber,ma_hb_cishu')->where($where)->select();
		if($res){
			$str = null;
			foreach($res as $v){
				$str .= $v['ma_type'].',';
			}
			$str = rtrim($str,',');
			return $this->getprizename($str);
		}
	}
	protected function getprizename($idarray){
		$idarray = explode(',',$idarray);
		$arr = array();
		foreach($idarray as $v){
			if(!empty($v)){
				$arr[] = $this->getprize($v);
			}
		}
		return $arr;
	}
	protected function getprize($id){
		$award = D(C('TABLE_AWARD'));
		if(!empty($id)){
			$where['id'] = $id;
			$res = $award->where($where)->find();
			return $res;
		}
	}



}